package com.bzy.blp.shiro;

import com.bzy.common.util.LoggerUtil;
import com.bzy.common.util.StringUtil;
import org.apache.shiro.subject.Subject;
import org.apache.shiro.web.filter.authc.LogoutFilter;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import java.util.Date;

public class CustomLogoutFilter extends LogoutFilter {

    @Override
    protected String getRedirectUrl(ServletRequest request, ServletResponse response, Subject subject) {
        // TODO Auto-generated method stub
        String redirect_uri = request.getParameter("redirect_uri");
        if (StringUtil.isBlank(redirect_uri)) {
            redirect_uri = super.getRedirectUrl(request, response, subject);
        }

        int index = redirect_uri.indexOf("?");
        if (index > 0) {
            redirect_uri = redirect_uri.substring(0, index);
        }

        String sign = (redirect_uri.contains("?") ? "&" : "?");
        redirect_uri += sign + "_=" + (new Date()).getTime();

        LoggerUtil.shiroLog("CustomLogoutFilter.java--getRedirectUrl--redirect_uri=" + redirect_uri);

        return redirect_uri;
    }
}
